<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>简易计算器</div>
        <div>
            <span>数值A：</span>
            <span>
                <input type="text" v-model='a' @keyup.enter='handle4' @keyup.delete='handle3'>
                <!-- 添加按键修饰符 回车 和 删除 事件 -->
            </span>
        </div>
        <div>
            <span>数值B：</span>
            <span>
                <input type="text" v-model='b' @keyup.enter='handle1' @keyup.delete='handle2'>
            </span>
        </div>
        <button @click='handle'>点击</button>
        <span>计算结果：</span>
        <span>{{result}}</span>
    </div>
    <script src="../vue.js"></script>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                a: '',
                b: '',
                result: ''
            },
            methods: {
                handle() {
                    this.result = parseInt(this.a) + parseInt(this.b)
                },
                handle1() {
                    this.result = parseInt(this.a) + parseInt(this.b)
                },
                handle2() {
                    this.b = ''
                },
                handle3() {
                    this.a = ''
                },
                handle4() {
                    this.result = parseInt(this.a) + parseInt(this.b)
                }
            }
        })
    </script>
</body>

</html>